﻿
using System.IO;
using System.Collections.Generic;
using System.Linq;

namespace Eugenhome.Atrium
{
    /// <summary>
    /// 
    /// </summary>
    public class BaseFile
    {
        /// <summary></summary>
        public string ImageFolder { get; private set; }

        /// <summary></summary>
        public string FullFileName { get; set; }

        /// <summary></summary>
        public string DisplayName { get { return FullFileName!=null? Path.GetFileName(FullFileName):""; } }

        /// <summary></summary>
        public string HttpPath { get { return ImageFolder + "/" + Path.GetFileName(FullFileName); } }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="imageFolder"></param>
        /// <param name="fullFileName"></param>
        protected BaseFile(string imageFolder, string fullFileName)
        {
            ImageFolder = imageFolder;
            FullFileName = fullFileName; 
        }

        //public BaseFile(string fullFileName) { }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="rootPath"></param>
        /// <returns></returns>
        public List<BaseFile> GetFiles(string rootPath)
        {
            string dir = Path.Combine(rootPath, ImageFolder);
            if (!Directory.Exists(dir))
                Directory.CreateDirectory(dir);

            return Directory.GetFiles(dir).Select(item => new BaseFile(ImageFolder, item)).ToList();
        }

    }
}